home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / tool chest / development kits / mpw related / mpw script tips 1.1.1 / sample scripts / a2hex next >
Encoding:
Text File  |  1991-08-16  |  4.9 KB  |  138 lines

  1. #-----------------------------------------------------------------------------------------------------------------------------------------------------
  2. #    A2Hex
  3. #    MPW Shell Script
  4. #    
  5. #    Original by Stuart Davidson
  6. #    Changes by Gina Cherry • August 16, 1991
  7. #    Copyright:    © 1991 by Apple Computer, Inc., all rights reserved.
  8. #    
  9. #    Usage:    A2Hex [file]
  10. #    
  11. #    Function:
  12. #        A2Hex takes one or more lines of assembly language and computes the equivalent in 
  13. #        hexadecimal.   The assembly lines cannot contain variables, labels, or procedure
  14. #        headers.  If an input file is not specified, A2Hex prompts the user for a line of assembly
  15. #        language.  If an input file is specified, A2Hex converts the selected text in the input file 
  16. #        to hex.
  17. #
  18. #    Note:
  19. #        A2Hex can be added to the Tools menu with the following command:
  20. #                AddMenu Tools A2Hex 'A2Hex "{Active}" ∑∑ "{Worksheet}"'
  21. #----------------------------------------------------------------------------------------------------------------------------------------------------
  22.  
  23.  
  24.  
  25. #    The first section of this script consists of commands which are executed by the MPW Shell.
  26. #    These commands are ignored by StreamEdit, because of the semi-colon in the first column.
  27.  
  28. #----------------------------------------------------------------------------------------------------------------------------------------------------
  29. #    Shell Commands
  30. #----------------------------------------------------------------------------------------------------------------------------------------------------
  31.  
  32. ;    #    If more than one parameter was given, write error message and exit script.    
  33. ;        If {#} > 1
  34. ;            Echo "### Usage: {0} [file]" >> Dev:StdErr
  35. ;            Exit 1
  36. ;        End
  37. ;
  38. ;    #    Don't exit on error.
  39. ;        Set Exit 0
  40. ;
  41. ;    #    Write procedure header to temporary file.
  42. ;        Echo 'FOO    PROC' > "{0}Temp.a"
  43. ;
  44. ;    #    If an input file was specified:
  45. ;        If {#} == 1
  46. ;        #    Copy selected text from input file to clipboard.
  47. ;            Copy § "{1}" ≥ Dev:Null
  48. ;        #    Exit if no text is selected in the input file.
  49. ;            If {Status} != 0
  50. ;                Delete {0}Temp.a
  51. ;                Exit 0
  52. ;            End
  53. ;        #    Save value of {NewWindowRect}
  54. ;            Set OldWindowRect "{NewWindowRect}"
  55. ;        #    Want to open a small workspace.
  56. ;            Set NewWindowRect 0,0,100,100
  57. ;        #    Open temporary file.
  58. ;            Open {0}Temp.a
  59. ;        #    Restore old value of {NewWindowRect}
  60. ;            Set NewWindowRect "{OldWindowRect}"
  61. ;        #    Append text from clipboard to temporary file.
  62. ;            Paste ∞ {0}Temp.a 
  63. ;        #    Write a newline to temporary file.
  64. ;            Echo >> {0}Temp.a
  65. ;        #    Insert tabs.
  66. ;            #    Set count to the number of lines in the temporary file.
  67. ;                Set count `Count -l {0}Temp.a`
  68. ;            #    Loop through lines.
  69. ;                Loop
  70. ;                #    Break if on first line.
  71. ;                    Break if {count} == 1
  72. ;                #    Position cursor at beginning of current line.
  73. ;                    Find Δ{count} {0}Temp.a
  74. ;                #    Insert tab at beginning of line.
  75. ;                    Replace /(≈)®1/ ∂t®1 {0}Temp.a
  76. ;                #    Decrement count.
  77. ;                    Set count `evaluate {count} -1`
  78. ;                End    
  79. ;            
  80. ;        #    Close temporary file
  81. ;            Close -y {0}Temp.a
  82. ;
  83. ;    #    If no input file was specified:  
  84. ;        Else 
  85. ;        #    Request a line of assembly code.
  86. ;            Set assembly "`Request "Assembly to hex:"`" 
  87. ;        #    If Cancel button was chosen, delete temporary file and exit script.
  88. ;            If "{assembly}" == ""
  89. ;                Delete {0}Temp.a
  90. ;                Exit 0
  91. ;            End    
  92. ;        #    Write assembly code to temporary file.
  93. ;            Echo -n ∂t >> {0}Temp.a
  94. ;            Echo "{assembly}" >> {0}Temp.a
  95. ;        End
  96. ;
  97. ;        Echo "∂tRTS" >> {0}Temp.a
  98. ;        Echo "∂tENDPROC" >> {0}Temp.a
  99. ;        Echo "∂tEND" >> {0}Temp.a
  100. ;
  101. ;    #    Assemble temporary file.
  102. ;        Asm {0}Temp.a
  103. ;
  104. ;    #    If assembly fails, exit script.
  105. ;        If {Status} != 0
  106. ;            Echo "### {0}: Assembly failed." >> StdErr
  107. ;            Exit 3
  108. ;        End
  109. ;
  110. ;    #    Pipe output of Dumpobj to StreamEdit command.  Dumpobj writes disassembled code to standard
  111. ;    #    output.  StreamEdit executes the StreamEdit statements at the bottom of this file to extract the 
  112. ;    #    hex equivalent of the assembly input from the Dumpobj output.  The call to StreamEdit uses 
  113. ;    # the command Which "{0}", which expands into the name of the currently running shell script.  
  114. ;    #    The -d option causes StreamEdit to discard text from the input file, writing only the output
  115. ;    #    from print statements to standard output.
  116. ;        Dumpobj -m FOO {0}Temp.a.o | StreamEdit -d -s `Which "{0}"`
  117. ;
  118. ;    #    Delete temporary file(s).
  119. ;        Delete {0}Temp≈
  120. ;
  121. ;    #    Exit shell script.
  122. ;        Exit
  123.  
  124.  
  125.  
  126. #----------------------------------------------------------------------------------------------------------------------------------------------------
  127. #    StreamEdit Statements
  128. #----------------------------------------------------------------------------------------------------------------------------------------------------
  129.  
  130. #    These statements are meant to operate on the output of the Dumpobj shell command.  They write 
  131. #    each instruction (except the RTS instruction) in both assembly and hexadecimal to standard 
  132. #    output.
  133.  
  134. #    Find all hex lines except the one representing the RTS instruction.
  135.     (!/[0-9]«8»:≈RTS≈/) && (/[0-9]«8»: ([0-9a-fA-F ]+)®1≈∂'≈∂'[ ]+([¬ ∂n]+≈)®2/) 
  136.     #    Print hex and assembly equivalent to output file.
  137.         print ®1'#'®2
  138.